package com.lty.jeeg.server.modules.fas.dao;

import com.lty.jeeg.server.modules.fas.dto.BorrowDTO;
import com.lty.jeeg.server.modules.fas.model.Borrow;
import com.lty.jeeg.server.modules.fas.vo.BorrowVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author : xuchen
 * @date : 2019-03-02
 * Description : 借用
 */
@Mapper
@Repository
public interface BorrowDao {

    /**
     * 根据ID获取
     * @param id ID
     * @return bean
     */
    BorrowDTO getById(Long id);

    /**
     * 删除
     * @param id ID
     * @return 1/0
     */
    @Delete("update fas_borrow set isDeleted = '1' where id = #{id}")
    int delete(Long id);

    /**
     * 修改
     * @param borrow
     * @return 1/0
     */
    int update(Borrow borrow);

    /**
     * 保存
     * @param borrow bean
     * @return ID
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into fas_borrow(name, lenderPersonnel, lenderDepartment, borrowerPersonnel, borrowerDepartment, " +
            "estimateReturnTime, actualReturnTime, goodsId, borrowerNum, flowState, remark, createBy, updateBy, isDeleted) " +
            "values(#{name}, #{lenderPersonnel}, #{lenderDepartment}, #{borrowerPersonnel}, #{borrowerDepartment}, " +
            "#{estimateReturnTime}, #{actualReturnTime}, #{goodsId}, #{borrowerNum}, #{flowState}, #{remark}, #{createBy}" +
            ", #{updateBy}, #{isDeleted})")
    Long save(Borrow borrow);

    /**
     * 计数
     * @param params 筛选条件
     * @return 总数
     */
    int count(@Param("params") Map<String, Object> params);

    /**
     * 列表
     * @param params 筛选条件
     * @param offset 页码
     * @param limit 分页数目
     * @return beanList
     */
    List<BorrowVO> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

}
